package com.exartisan.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import com.exartisan.thanhdoanhn.R;

public class GalleryMenuDropDown implements SpinnerAdapter {

	Context context;
	ArrayList<String> items;
	int checkPosition;
	LayoutInflater inflater;
	boolean isPhoto;

	public GalleryMenuDropDown(Context context) {
		this.context = context;
		items = new ArrayList<String>();
		inflater = LayoutInflater.from(context);
		items.add("Ảnh");
		items.add("Video");
		isPhoto = true;
	}

	public void setSelectedPosition(int checkPosition) {
		this.checkPosition = checkPosition;
	}
	
	public boolean isSelectedPhoto(){
		return isPhoto;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getItemViewType(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		TitleViewHolder holder = new TitleViewHolder();
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.spinner_title, null);
			holder.tvTitle = (TextView) convertView.findViewById(R.id.tvSpinnerTitle);
			convertView.setTag(holder);
		} else
			holder = (TitleViewHolder) convertView.getTag();
		if(items.get(position).equals("Ảnh")) isPhoto = true;
		else isPhoto = false;
		holder.tvTitle.setText(items.get(position));
		return convertView;
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isEmpty() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void registerDataSetObserver(DataSetObserver arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void unregisterDataSetObserver(DataSetObserver arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup arg2) {
		DropdownViewHolder dropdownHolder = new DropdownViewHolder();
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.row_gallery_menu_dropdown, null);
			dropdownHolder.tvIndex = (TextView) convertView
					.findViewById(R.id.tvItem);
			dropdownHolder.layoutBackground = (RelativeLayout) convertView.findViewById(R.id.layout_background);
			convertView.setTag(dropdownHolder);
		} else
			dropdownHolder = (DropdownViewHolder) convertView.getTag();
		if(checkPosition!=position)
			dropdownHolder.layoutBackground.setBackgroundColor(Color.parseColor("#404040"));
		else 
			dropdownHolder.layoutBackground.setBackgroundColor(Color.parseColor("#2789AF"));
		dropdownHolder.tvIndex.setText(items.get(position));
		return convertView;
	}

	class TitleViewHolder {

		TextView tvTitle;
	}

	/**
	 * The Class DropdownViewHolder.
	 * 
	 * @author anh
	 */
	class DropdownViewHolder {

		TextView tvIndex;

		RelativeLayout layoutBackground;
	}

}
